package com.bj58.migrate.condition.reader;

import java.io.File;

import com.bj58.migrate.condition.ConditionReader;
import com.bj58.migrate.helper.Helper;

public class CateConditionReader implements ConditionReader{

    public File[] getConditionFileList( String[] args ){

        if( args.length < 2 ){
            return null;
        }

        String num = args[ 2 ];

        File taskDirectory = Helper.seekFile( "task" );
        if( taskDirectory.isDirectory() && taskDirectory.listFiles() != null ){
            int index = Integer.parseInt( num ) - 1;
            if( index >= taskDirectory.listFiles().length ){
                return null;
            }
            File runFile = null;
            for( int i = 0; i < 4; i++ ){
                File tmpFile = taskDirectory.listFiles()[ i ];
                if( tmpFile.getName().equals( "" + num.trim() ) ){
                    runFile = tmpFile;
                    break;
                }
            }

            if( ( runFile != null ) && ( runFile.exists() ) && ( runFile.listFiles() != null ) ){
                return runFile.listFiles();
            }
        }

        return null;
    }
}
